package Thread;

/*
在linux中 , linux内核把线程看做是轻量级进程
 */

//join线程等待
public class Test21 {
    //指定时间等待TIMID_WAITING
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            System.out.println("t线程");
            try {
                //指定时间等待
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t.start();
        //下面的等待时间需要比t线程中的短
        Thread.sleep(50);
        System.out.println(t.getState());
    }
    //就绪状态RUNNABLE,表示正在CPU上运行
    //或者随时准备去CPU上运行
    public static void main4(String[] args) {
        Thread t = new Thread(()->{
            while (true);
        });
        t.start();
        System.out.println(t.getState());
    }
    //线程已经执行完毕的状态TERMINALED
    public static void main3(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            System.out.println("我是t线程");
        });
        t.start();
        Thread.sleep(1000);
        System.out.println(t.getState());
    }
    //线程的new状态
    public static void main2(String[] args) {
        Thread t = new Thread(()->{
           while (true){
               System.out.println("t线程");
           }
        });
        //还没有通过start启动线程 , 此时它的状态是new
        System.out.println(t.getState());
    }
    static int count = 3;
    public static void main1(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while (count > 0){
                System.out.println(count--);
            }
        });
        t.start();
        t.join();
        System.out.println("我是main线程");
    }
}
